/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcn.dal.hibernate;

import com.rcn.dal.interfaces.IBaseDAO;
import com.rcn.domain.Paciente;
import com.rcn.exception.RaccoonException;
import com.rcn.hibernate.GestorBD;
import java.util.List;
import javax.persistence.Table;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Nicolas
 */ 
public class BaseDAO implements IBaseDAO{

    public <T> void save(T item) throws RaccoonException{
        try{
            GestorBD.getGestorBD().save(item);
        }catch(HibernateException e){
            throw new RaccoonException(e.getMessage(),e.getCause());
        }
        
    }

    public <T> void update(T item) throws RaccoonException{
        try{
            GestorBD.getGestorBD().update(item);
        }catch(HibernateException e){
            throw new RaccoonException(e.getMessage(), e.getCause());
        }
    }

    public <T> void saveOrUpdate(T item) throws RaccoonException{
        try{
            GestorBD.getGestorBD().saveOrUpdate(item);
        }catch(HibernateException e){
            throw new RaccoonException(e.getMessage(), e.getCause());
        }
    }
    
    public <T> void saveOrUpdate(T item,Session s) throws RaccoonException{
        try{
            GestorBD.getGestorBD().saveOrUpdate(item,s);
        }catch(HibernateException e){
            throw new RaccoonException(e.getMessage(), e.getCause());
        }
    }
    
    public Object getById(Class clazz, String id)throws RaccoonException{
        try{
            return GestorBD.getGestorBD().getData(clazz, id);
        }catch(HibernateException e){
            throw new RaccoonException(e.getMessage(), e.getCause());
        }
    }

    public List getAll(Class clazz)throws RaccoonException{
        try{
            return GestorBD.getGestorBD().getAll(clazz.getName());
        }catch(HibernateException e){
            throw new RaccoonException(e.getMessage(), e.getCause());
        }
    }

    public <T> void delete(T item)throws RaccoonException{
        try{
            GestorBD.getGestorBD().delete(item);
        }catch(HibernateException e){
            throw new RaccoonException(e.getMessage(), e.getCause());
        }
    }
}
